<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:text name="category.list.title"/></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
	<script type="text/javascript" src="${ctx}/js/jquery.progressbar2.js"></script>
	<script type="text/javascript" src="${ctx}/js/publish.js"></script>
 
	<script type="text/javascript">
		
		function loadAuditors(type,cId){
			$.ajax({
				url:"${ctx}/category/category-auditors.action",
				data:{"auditType":type,"targetId":cId,"t":new Date().getTime()},
				dataType:'text',
				type:'post',
				success:function(data){
					try{ 
						var json = eval('('+data+')');
						if(json.flag){
							$("#auditor_"+cId).html(json.auditor);
						}else{
							alert(cId+'_false');
						}				
					}catch(e){				
					}
				},
				error:function(){
				}		
			});	
		}
	</script>
</head>
<body>
<s:set name="siteId" value="#session['CURRENT_SITE'].siteId"></s:set>
<s:hidden name="#siteId" id="sizeno"/>
<s:hidden name="simpname" id="simpname"/>
<s:hidden name="psimpname" id="psimpname"/>

<div id="wrapper">
	<div id="main_box">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="category.title"/></div>
	<div class="listtit" id="listtit"><p><span><strong><s:text name="category.list.title"/></strong></span></p></div>
	
	<s:hidden name="childId" id="childId"/>
	
	<s:form action="category-list" id="action_form">
	<div id="siteAddDiv" >
		<br/>
		<s:text name = "siteIndexTpl"/>:<s:textfield id="siteIndex" name="site.siteIndexTpl" required="true" requiredposition="right" cssClass="txtin" readonly="true"/>
		<a href="#"  onclick="selectIndex()">&nbsp;<s:text name="choice"/></a>
		<input type="button" value="<s:text name="save"/>" class="btnlist2" id="tpl_save_btn"/>
		<br/><br/>
	</div>
	<div class="listoperate">
		<span class="cssa">
			<s:if test="%{authLicence('2_2_2',#siteId)}">
				<input id="top_new_btn" type="button" value="<s:text name="new"/>" class="btnadd"/>
			</s:if>
			<s:elseif test="%{authLicence('3_3_1',category.categoryId)}">
				 <input id="top_new_btn" type="button" value="<s:text name="new"/>" class="btnadd"/>
			</s:elseif>
			<s:else>
				<input id="top_new_btn" disabled="disabled" type="button" value="<s:text name="new"/>" class="btnadd"/>
			</s:else>
		</span>
		<span>
				<input type="button" value="<s:text name="anti-selection"/>" class="btnlist2" id="top_anti_btn"/>
				<input type="button" value="<s:text name="delete"/>" class="btnlist2" id="top_del_btn"/>
				<input type="button" value="<s:text name="merge"/>" class="btnlist2" id="top_merge_btn"/>
				<input type="button" value="<s:text name="move"/>" class="btnlist2" id="top_move_btn"/>
				<input type="button" value="<s:text name="enable"/>" class="btnlist2" id="top_enable_btn"/>
				<input type="button" value="<s:text name="disable"/>" class="btnlist2" id="top_disable_btn"/>
				<input type="button" value="<s:text name="authorSet"/>" class="btnlist4" id="top_author_btn"/>
				<input type="button" value="<s:text name="文章迁移"/>" class="btnlist4" id="top_movecontent_btn"/>
		</span>
	</div>
	<div class="listbox" id="listbox">
		<s:hidden name="category.categoryId" id="categoryId"/>
		<table class="listgrid" id="listbox">
			<tbody>
				<tr>
					<th><input type="checkbox" name="all" id="all_check"/></th>
					<th><s:text name="category.ord"/></th>
					<th><s:text name="category.catName"/></th>
					<th><s:text name="category.catSimpleName"/></th>
					<th><s:text name="contentNum"/></th>
					<th><s:text name="categoryStatus"/></th>
					<th><s:text name="category.auditor"/></th>
					<th><s:text name="operate"/></th>
				</tr>
				<s:iterator value="page.result" status="n">
					<tr categoryId="<s:property value="categoryId"/>">
						<td><input type="checkbox" name="key" value="<s:property value="categoryId"/>"/></td>
						<td class="ord"><s:property value="ord"/></td>
						<td align="left"><s:property value="catName"/>&nbsp;</td>
						<td><s:property value="catSimpleName"/>&nbsp;</td>
						<td><s:property value="contentNum"/></td>
						<td>
							<s:if test="categoryStatus == true"><s:text name="yetEnable"/></s:if><s:else><span id="categoryStatus_meg" style="color:red;"><s:text name="yetDisable"/></span></s:else>&nbsp;
						</td>
						<td  id="auditor_<s:property value="categoryId"/>"></td>
						<td>
						<s:if test="%{authLicence('3_3_1',categoryId)}">
							<a href="#this" onclick="upMove('<s:property value="categoryId"/>',this)"><s:text name="up"/></a><tt>|</tt>
						    <a href="#this" onclick="downMove('<s:property value="categoryId"/>',this)"><s:text name="down"/></a><tt>|</tt>
							<a href="#this" onclick="goCatEdit('<s:property value="categoryId"/>')"><s:text name="edit"/></a><tt>|</tt>
						    <a href="#this" onclick="goCatDel('<s:property value="categoryId"/>')"><s:text name="delete"/></a><tt>|</tt>
						    <a href="#this" onclick="goDynamicPreview('<s:property value="categoryId"/>')"><s:text  name="dynamicPreview"/></a><tt>|</tt>
						    <a href="#this" onclick="goStaticPreview('<s:property value="categoryId"/>')"><s:text name="staticPreview"/></a><tt>|</tt>
						</s:if>
						<s:else>
							<s:text name="up"/><tt>|</tt>
						    <s:text name="down"/><tt>|</tt>
							<s:text name="edit"/><tt>|</tt>
						    <s:text name="delete"/><tt>|</tt>
						    <s:text  name="dynamicPreview"/><tt>|</tt>
						    <s:text name="staticPreview"/><tt>|</tt>
						 </s:else>
						 <s:if test="%{authLicence('3_3_2',categoryId)}">
						    <a href="#this" id="publish" onclick="goPublish('<s:property value="categoryId"/>')"><s:text name="publish"/></a><tt>|</tt>
						 </s:if>
						 <s:else>
						    <s:text name="publish"/><tt>|</tt>
						 </s:else>
						<s:if test="%{authLicence('3_3_1',categoryId)}">
						    <a href="#this" onclick="disableOrEnable('<s:property value="categoryId"/>',<s:if test="categoryStatus==1">1</s:if><s:else>2</s:else>);"><s:if test="categoryStatus==1"><s:text name="disable"/></s:if><s:else><s:text name="enable"/></s:else></a><tt>|</tt>
						    <a href="#this" onclick="$$.shade('#<s:property value="categoryId"/>','#lightclose,#closebtn,#lightsubmit,#moev_top','#lightbox','321');goMove('<s:property value="categoryId"/>')" name="moveCate" id="<s:property value="categoryId"/>"><s:text name="move"/></a><tt>|</tt>
						    <a href="#this" onclick="$$.shade('#<s:property value="categoryId"/>mer','#merlightclose,#merlightsubmit,#merclosebtn','#marlightbox','321');goMerge('<s:property value="categoryId"/>');" name="mergeCate" id="<s:property value="categoryId"/>mer"><s:text name="merge"/></a><tt>|</tt>
						    <a href="#this" onclick="goNnter('<s:property value="categoryId"/>')"><s:text name="enter"/></a>
						</s:if>
						<s:else>
						    <s:if test="categoryStatus==1"><s:text name="disable"/></s:if><s:else><s:text name="enable"/></s:else></a><tt>|</tt>
						    <s:text name="move"/><tt>|</tt>
						    <s:text name="merge"/><tt>|</tt>
						    <s:text name="enter"/>
						</s:else>
						</td>
					</tr>
					<script type="text/javascript">
						loadAuditors('category','<s:property value="categoryId"/>');
					</script>
				</s:iterator>
			</tbody>
		</table>
		
	</div>
	<div class="listoperateb ">
		<span>
				<input type="button" value="<s:text name="anti-selection"/>" class="btnlist2" id="bottom_anti_btn"/>
				<input type="button" value="<s:text name="delete"/>" class="btnlist2" id="bottom_del_btn"/>
				<input type="button" value="<s:text name="merge"/>" class="btnlist2" id="bottom_merge_btn"/>
				<input type="button" value="<s:text name="move"/>" class="btnlist2" id="bottom_move_btn"/>
				<input type="button" value="<s:text name="enable"/>" class="btnlist2" id="bottom_enable_btn"/>
				<input type="button" value="<s:text name="disable"/>" class="btnlist2" id="bottom_disable_btn"/>
				<input type="button" value="<s:text name="authorSet"/>" class="btnlist4" id="bottom_author_btn"/>
		</span>
	</div>
	</s:form>
</div>

</div>
<!-- 栏目移动层 -->
<div id="lightbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose" class="lightclose" /><strong>栏目移动</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit">请选择要移动的栏目</div>
		<div class="ilghtmainbox">			 
			<div id="treeDiv_MoveCat"  class="ztree" style="overflow-y:auto;overflow-x:auto;height:250px;"></div>
		</div>
		<div class="lightbtnbox"><input type="button" value="移动至顶级栏目" id="moev_top" class="btnlist4" onclick="goCattop()"/><input type="button" value="确认" id="lightsubmit" class="btnlist2" onclick="goCatMove()"/><input type="button" value="取消" id="closebtn" class="btnlist2" /></div>
	</div>
</div>
<!-- 栏目合并层 -->
<div id="marlightbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="merlightclose" class="lightclose" /><strong>栏目合并</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit">请选择要合并的栏目</div>
		
		<div class="ilghtmainbox">
		<span style="color: #457d07">友情提示：如果源栏目下有文章，并且目标栏目下有子栏目，移过去的文章将不可见，您可以及时进行文章迁移。</span>
			<div id="treeDiv_MerCat"  class='ztree' style="overflow-y:auto;overflow-x:auto;height:250px;"></div>
		</div>
		<div class="lightbtnbox"><input type="button" value="确认" id="merlightsubmit" class="btnlist2" onclick="goCatMerge()"/><input type="button" value="取消" id="merclosebtn"  class="btnlist2" /></div>
	</div>
</div>
<!-- 审核人设置层 -->
<div id="autherlightbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="autherlightclose" class="lightclose" /><strong>审核人设置</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit">请选择审核人</div>
		<div class="ilghtmainbox">
			<div id="authorSetDiv"></div>
		</div>
		<div class="lightbtnbox"><input type="button" value="确认" id="autherlightsubmit" class="btnlist2" onclick="authorSet()"/><input type="button" id="autherclosebtn" value="关闭"  class="btnlist2" /></div>
	</div>
</div>
<!-- 栏目发布层 -->
<div id="lightbox_c" class="lightbox" >
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose_c" class="lightclose" /><strong>发布站点</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit"><label id="returnInfo">正在发布栏目....</label>
		</div>
		<div id="progressBar_bg">
			<span class="progressBar" id="pb2"></span>
			<span id="progressBar_bh"></span>
		</div>
		<div class="lightbtnbox"><input type="button" value="确认" id="lightsubmit_c" class="btnlist2"/><input type="button" value="停止" id="stoppublish" class="btnlist2"/></div>
	</div>
</div>
<!-- 栏目文章迁移层 -->
<div id="lightbox_m" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose_m" class="lightclose" /><strong>文章迁移</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit">请选择要迁移至的栏目</div>
		
		<div class="ilghtmainbox">
		<span style="color: #457d07"></span>
			<div id="treeDiv_MoveContent"  class="ztree" style="overflow-y:auto;overflow-x:auto;height:250px;"></div>
		</div>
		<div class="lightbtnbox"><input type="button" value="确认" id="lightsubmit_m" class="btnlist2" onclick="goMoveContent()"/><input type="button" value="取消" id="closebtn_m"  class="btnlist2" /></div>
	</div>
</div>
</body>
</html>
<script type="text/javascript" defer="defer">
	
	var ctx = '${ctx}';
	//得到父栏目ID
	var categoryId = $("#categoryId").val();
	//判断-顶级栏目列表显示站点首页模板设置
	var siteId=$("#sizeno").val();
	var check_bind="yes";
	if(categoryId == null || categoryId == ""){
		$("#siteAddDiv").show();
		 $.post("${ctx}/site/site-getindextpl.action?site.siteId="+siteId,function(data){
			$("#siteIndex").val(data);
		}); 
	}else{
		$("#siteAddDiv").hide();
	}
	
	actionName = "category";	
	confirmStr = "<s:text name="delete.confirm"/>";
	chiocenothing = "<s:text name="chiocenothing"/>";
	$(function(){
 		$("#top_new_btn").click(goNewCate);
 		$("#top_anti_btn").click(antiSelect);
 		$("#top_del_btn").click(goBatchCatDel);
 		
		$("#top_enable_btn").click(batchEnable);
		$("#top_disable_btn").click(batchDisable);
 		$("#bottom_enable_btn").click(batchEnable);
		$("#bottom_disable_btn").click(batchDisable);
		
		$("#top_merge_btn").click(batchMarge);
		$("#top_move_btn").click(batchMove);
		$("#bottom_merge_btn").click(batchMarge);
		$("#bottom_move_btn").click(batchMove);
		
		$("#top_author_btn").click(batchAuthorSet);
		$("#bottom_author_btn").click(batchAuthorSet);
		
 		$("#bottom_del_btn").click(goBatchCatDel);
 		$("#bottom_anti_btn").click(antiSelect);
		$("#search_btn").click(search);
		$("#all_check").click(selAll);
		$("#extend").click(extend);
		
		$("#tpl_save_btn").click(saveIndexTpl);
		$("#top_movecontent_btn").click(moveContent);
		//移动
		$("#bottom_move_btn").bind('click', function(){
			var ids = inputvalue();
			if(ids=="on"||ids==""||ids==null){
				return; 
			}else{
				$$.shade("#bottom_move_btn","#lightclose,#closebtn,#lightsubmit","#lightbox","321");
			}
			
		 });
		//移动
		$("#top_move_btn").bind('click', function(){
			var ids = inputvalue();
			if(ids=="on"||ids==""||ids==null){
				return; 
			}else{
				$$.shade("#top_move_btn","#lightclose,#closebtn,#lightsubmit","#lightbox","321");
			}
		 });	
		//合并
		$("#bottom_merge_btn").bind('click', function(){
			var ids = inputvalue();
			if(ids=="on"||ids==""||ids==null){
				return; 
			}else{
				$$.shade("#bottom_merge_btn","#merlightclose,#merlightsubmit,#merclosebtn","#marlightbox","321");
			}
		 });
		//合并
		$("#top_merge_btn").bind('click', function(){
			var ids = inputvalue();
			if(ids=="on"||ids==""||ids==null){
				return; 
			}else{
				$$.shade("#top_merge_btn","#merlightclose,#merlightsubmit,#merclosebtn","#marlightbox","321");
			}
			
		 });
		
		//设置审核人
		 $("#bottom_author_btn").bind("click",function(){
			 	var ids = inputvalue();
				if(ids=="on"||ids==""||ids==null){
					if(check_bind!="no"){alert("您未选择任何一个");}					
					return; 
				}else{
					$$.shade("#bottom_author_btn","#autherlightclose,#autherclosebtn,#autherlightsubmit","#autherlightbox");
				}
				
		 });
		//设置审核人
		 $("#top_author_btn").bind("click",function(){
			    var ids = inputvalue();
				if(ids=="on"||ids==""||ids==null){
					if(check_bind!="no"){alert("您未选择任何一个");}	
					return; 
				}else{
					$$.shade("#top_author_btn","#autherlightclose,#autherclosebtn,#autherlightsubmit","#autherlightbox");
				}
				
		 });
		//栏目文章迁移
		 $("#top_movecontent_btn").bind("click",function(){
			    var ids = inputvalue();
				if(ids=="on"||ids==""||ids==null){
					if(check_bind!="no"){alert("您未选择任何一个");}	
					return; 
				}else{
					$$.shade("#top_movecontent_btn","#lightclose_m,#closebtn_m,#lightsubmit_m","#lightbox_m","321");
				}
				
		 });
		
		if('<s:property value="flag" />'!='' ){
			alert("删除成功");
		}
	});
	
	//进入子栏目管理页面
	function goNnter2(){
		var id = $("#categoryId").val();
		 if (window.navigator.userAgent.indexOf("Chrome")>=0){
			window.parent.frames["leftframe"].contentWindow.expandTarget("ztree_cat",id);
		 }
		else{
			window.parent.frames["leftframe"].expandTarget("ztree_cat",id);
		} 
	}
	function goNnter(categoryId){
		$("${ctx}/category/category-list.action?category.categoryId="+categoryId,function(data){
			if(data.length>0){
				document.location.href="${ctx}/category/category-list.action?category.categoryId="+categoryId;
			}else{
				alert("该栏目没有子栏目");
			}
		});
	}
	function synchronous(categoryId){
		/* if (categoryId){
			var now_onclick=$(window.parent.frames["leftframe"].frames["leftmenutree"].document).find(".dojoTreeNodeLabelSelected").parent("span").parent(".dojoTreeNode");
			var now_child=now_onclick.children("div").children(".dojoTreeNode");
			var temp;
			for(var i=0;i<now_child.length;i++){
				temp=now_child.eq(i).children("span").children("span").children("a").attr("href").replace("category-list.action?category.categoryId=","");
				if (temp==categoryId){break;}
			}
			if (now_child.eq(i).children("div").css("display")=="none"){
				now_child.eq(i).children("img").eq(now_child.eq(i).children("img").length-1).click();
			}
			//now_child.eq(i).children("span").children("span").children("a").get(0).click();
		}
		else {
			
		} */

		//now_child.eq(i).children("span").children("span").children("a").trigger("click");
		//alert("a");
		
			//now_onclick.children("img").eq(now_onclick.children("img").length-1).trigger("click")
			//now_onclick.children("img").eq(now_onclick.children("img").length-1).attr("src","/cms-web/struts/dojo/src/widget/templates/images/Tree/treenode_expand_minus.gif");
			//now_onclick.children("span").children("img").attr("src","/cms-web/struts/dojo/src/widget/templates/images/Tree/open.gif");
			//now_onclick.children("div").css({"display":"block","opacity":"0.999999"});
		//$(window.parent.frames["leftframe"].document).find("input[@type='radio']").attr("checked","true");
	}
	// 判断是新增父栏目还是子栏目
	function goNewCate(){
		if(categoryId == null || categoryId == ""){
			goNew();
		}else{
			gonewChild();
		}
	}
	//新增栏目
	function gonewChild(){
		document.location.href=actionName+"-input.action?category.category.categoryId="+categoryId;
	}
	//删除栏目
	function goCatDel(key){
		//删除栏目下标题为空的文章
		$.post("${ctx}/category/category-delnullcontent.action?category.categoryId="+key,function(data){});
		
		//检查栏目下是否有文章，删除
		$.post("${ctx}/category/category-checkischild.action?category.categoryId="+key,function(data){
			if(data == "yes"){
				alert("此栏目包含子栏目，不能删除");
			}else {
				$.post("${ctx}/category/category-checkhavecont.action?category.categoryId="+key,function(data){
					if(data == "yes"){
						alert("栏目中包含文章，不能删除");
					}else{
						if(confirm("确实要删除吗？")){
							document.location.href=actionName+"-delete.action?key="+key+"&category.category.categoryId="+categoryId;
							//$.post("${ctx}/category/category-tree.action?treeType=cat",function(data){});
							//window.parent.frames["leftframe"].frames["leftmenutree"].location="${ctx}/category/category-tree.action?treeType=cat";
						}
					}
				});
			}
		});
	}
	function merDel(key){
		document.location.href=actionName+"-delete.action?key="+key;
		window.location.reload(); 
	}
	//编辑栏目
	function goCatEdit(key){
		document.location.href=actionName+"-input.action?category.categoryId="+key+"&category.category.categoryId="+categoryId;
	}
	//上移
	function upMove(id,element){
			
			var current=$(element).parents("tr");
			var up=current.prev();
			if(up.length!=0 && up.prev().length!=0){
				var upId=up.attr("categoryId");
				var obj = {"category.categoryId":id,"upId":upId};
				 $.post("${ctx}/category/category-upmove.action",obj,function(data){
						var ord=current.find(".ord").text();
						current.find(".ord").text(up.find(".ord").text());
						up.find(".ord").text(ord);
						current.insertBefore(up);
				});
			}
		
	}
	//下移
	function downMove(id,element){
		var current=$(element).parents("tr");
		var down=current.next();
		if(down.length!=0){
		var upId=down.attr("categoryId");
		var obj = {"category.categoryId":id,"upId":upId};
		 $.post("${ctx}/category/category-downmove.action",obj,function(data){
			var ord=current.find(".ord").text();	
			current.find(".ord").text(down.find(".ord").text());
			down.find(".ord").text(ord);
			down.insertBefore(current);
		}); 
	}
	}
	
	//禁用/启用
	function disableOrEnable(id,dn){
		var myDate=new Date();
		var sign="";
		if(dn=="1"){
			sign="确实要禁用吗？";
		}else{
			sign="确实要启用吗？";
		}
		if(confirm(sign)){
			$.post("${ctx}/category/category-disableorenable.action?category.categoryId="+id+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("成功");
				}else{
					alert("失败");
				}		}); 
		}
	}
	var g = function(D) {
		if ( D.indexOf(" ") == -1){
			return ( D.substring(0,1) === "#") ? document.getElementById(D.substring(1,D.length)) : document.getElementsByTagName(D);
		}
		else {
			var ary = D.split(" ");
			return g(ary[0]).getElementsByTagName(ary[1]);
		}
	};
	function inputvalue(){
		var d = g("#listbox input"), i = 0, j = d.length, str = "";
	    for ( ; i < j ; i ++ ) {
				str += (d[i].type == "checkbox" && d[i].id != "totalCheck" && d[i].checked == true ) ? d[i].value + "@" : "";
		};	
		return (str.slice(0,-1));
	};
	
	//批量禁用
	function batchDisable(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			return; 
		}else{
			check_bind="yes";
		}
		if(!ids){
			alert("请选择要禁用的栏目");
			return;		
		}
		var myDate=new Date();
		if(confirm("确实要禁用吗？")){
			$.post("${ctx}/category/category-batchdisable.action?ids="+ids+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("成功");
				}else if(data == "sorry"){
					alert("您没有权限");
				}else{
					alert("失败");
				}
			});
		}
	}
	//批量启用
	function batchEnable(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			return; 
		}else{
			check_bind="yes";
		}
		if(!ids){
			alert("请选择要启用的栏目");
			return;		
		}
		var myDate=new Date();
		if(confirm("确实要启用吗？")){
			$.post("${ctx}/category/category-batchenable.action?ids="+ids+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("成功");
				}else if(data == "sorry"){
					alert("您没有权限");
				}else{
					alert("失败");
				}		});
		}
		 
	}
	 
	//移动栏目弹出窗口
	var move_ids;
	var disabled_ids = "";
	var srcid = "";
	var childid = "";
	function goMove(srcId){ 
		$.post("${ctx}/category/category-findchildid.action?category.categoryId="+srcId,function(data){
			  $("#childId").val(data);
			  var childid = $("#childId").val();
			  disabled_ids = srcId+"@"+childid;
			  srcid = srcId;
			  var array_ = new Array();
			  array_.push(srcId); 
			  loadZTree(array_,'treeDiv_MoveCat'); 	
		});  
	}
	//批量移动选择
	var fla="";
	var idS;
	function batchMove(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			return; 
		}else{
			check_bind="yes";
		}
		if(!ids){
			alert("请选择要移动的栏目");
			return;		
		}
		idS = ids;
		fla = "batch";
		$.post("${ctx}/category/category-findchildids.action?ids="+ids,function(data){
				$("#childId").val(data);
				var childid = $("#childId").val();
				disabled_ids = ids+"@"+childid;
				var array_ = disabled_ids.split("@");
				loadZTree(array_,'treeDiv_MoveCat'); 
			});  
			
		}
	//移动处理
	function goCatMove(){
		var treeObj = $.fn.zTree.getZTreeObj('treeDiv_MoveCat');
		nodes = treeObj.getCheckedNodes(true);
		if(nodes){
			var targetId = nodes[0].id;
			if(!targetId){
				alert('请选择目标栏目');
				return ;
			}  
			if(fla=="batch"){
				if(confirm("确实要移动栏目吗？")){
					$.post("${ctx}/category/category-batchcatmove.action?ids="+idS+"&parentId="+targetId,function(data){
						if(data == "no"){
							alert("您没有权限");
						}else{
							alert("移动成功");
							window.location.reload(); 
							self.parent.leftframe.loadCatetree(true,true,'ztree_cat');
						}
					});
					}
			}else{
				if(confirm("确实要移动栏目吗？")){
					$.post("${ctx}/category/category-catmove.action?category.categoryId="+srcid+"&parentId="+targetId,function(data){
							alert("移动成功");
							window.location.reload(); 
							self.parent.leftframe.loadCatetree(true,true,'ztree_cat');
					});
				}
			}
		}
	}
	
	//合并栏目弹出窗口
	function goMerge(srcId){
		$.post("${ctx}/category/category-findchildid.action?category.categoryId="+srcId,function(data){
			$("#childId").val(data);
			var childid = $("#childId").val();
		  	disabled_ids = srcId+"@"+childid;
		  	
		  	srcid = srcId;
		  	fla = "single";
		  	var array_ = disabled_ids.split("@");
			loadZTree(array_,'treeDiv_MerCat');
		});  
	}
	//批量合并选择
	function batchMarge(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			check_bind="no";
			return; 
		}else{
			check_bind="yes";
		}
		if(!ids){
			alert("请选择要合并的栏目");
			return;	
		}
		idS = ids;
		fla = "batch"; 
		$.post("${ctx}/category/category-findchildids.action?ids="+ids,function(data){
			$("#childId").val(data);
			var childid = $("#childId").val();
			disabled_ids = ids+"@"+childid;
			var array_ = disabled_ids.split("@");
			loadZTree(array_,'treeDiv_MerCat');
		});  
	}
	//合并处理
	function goCatMerge(){
		var treeObj = $.fn.zTree.getZTreeObj('treeDiv_MerCat');
		nodes = treeObj.getCheckedNodes(true);
		if(nodes){
			var targetId = nodes[0].id;
			if(!targetId){
				alert('请选择合并的目标栏目');
				return;
			}
			//把源栏目的父id改为目标id
			if(idS != null){
				arr=idS.split("@"); 
				
			}
			if(fla=="batch"){
				if(confirm("确实要合并栏目吗？")){
					$.post("${ctx}/category/category-batchcatmerge.action?ids="+idS+"&parentId="+targetId,function(data){
						alert("合并成功");
						window.location.reload();
						self.parent.leftframe.loadCatetree(true,true,'ztree_cat');
					});
				}
			}else{
				if(confirm("确实要合并栏目吗？")){
					$.post("${ctx}/category/category-catmarge.action?category.categoryId="+srcid+"&parentId="+targetId,function(data){
						alert("合并成功");
						window.location.reload(); 
						self.parent.leftframe.loadCatetree(true,true,'ztree_cat');
					});
				}
			}
		}
	}
	
	//批量删除
	function goBatchCatDel(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			check_bind="no";
			return; 
		}else{
			check_bind="yes";
		}
		if(!ids){
			alert("请选择要删除的记录");
			return;		
		}
		//删除栏目下标题为空的文章
		$.post("${ctx}/category/category-delnullcontent.action?ids="+ids,function(data){});
		if(confirm("确实要删除栏目吗？")){
			$.post("${ctx}/category/category-batchcatdel.action?ids="+ids,function(data){
				if(data == "yes"){
					alert("您选择的栏目中包含子栏目,请重新选择");
				}else if(data == "sorry"){
					alert("您没有权限");
				}else{
					$.post("${ctx}/category/category-checkhavecont.action?ids="+ids,function(data){
						if(data == "no"){
							alert("你选择的栏目中包含文章，请重新选择");
						}else if(data == "sorry"){
							alert("您没有权限");
						}else{
							alert("删除成功");
							window.location.reload(); 
						}
					});
				}
			}); 
		}
	}
	//动态预览
	function goDynamicPreview(catId){
		var url = "${ctx}/generate/preview.action?targets="+catId+"&type=cat"; 
		window.open(url,'olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes'); 
	}
	//静态预览
	function goStaticPreview(catId){
		$.post("${ctx}/category/category-getsimplename.action?category.categoryId="+catId,function(data){
			var json = eval('('+data+')');
			if(json.flag){
				window.open(json.url,'olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes');
			}else{
				alert("栏目未发布，无法进行静态预览!");
			}
		});
	}
	//发布
	function goPublish(catId){
		$("#stoppublish").attr("disabled","");
		$$.shade("#publish","#lightclose_c,#lightsubmit_c","#lightbox_c","300");
		publishCats(catId,"all");
	}
	$("#stoppublish").click(function(){
		stopPublish();
	});
	$("#lightclose_c").click(function(){
		initBar();
	});
	$("#lightsubmit_c").click(function(){
		initBar();
	});
	function initBar(){
		$('#pb2').progressBar(0);
	}
	$(document).ready(function (){
		$("#pb2").progressBar({ barImage: '../images/progressbg_yellow2.gif'} );
	});
	//栏目首页模板
	function selectIndex(){
		var url = "${ctx}/theme/file-select.action?type=index&prefix=index&suffix=tpl&elementId=siteIndex"; 
		window.open(url); 
	}
	//保存站点首页模板
	function saveIndexTpl(){
		var siteId=$("#sizeno").val();
		var siteIndex = $("#siteIndex").val();
		var obj = {"site.siteId":siteId,"site.siteIndexTpl":siteIndex};
		$.post("${ctx}/site/site-saveindextpl.action",obj,function(data){
			if(data == "ok"){
				alert("站点首页模板保存成功");
			}
		});
	}
$(function(){
	reloadTree();
	goNnter2();
});
///移动至顶级栏目
function goCattop(){
	var ids = inputvalue();
	$.post("${ctx}/category/category-checkTopCategory.action?ids="+idS,function(data){
		if(data=="no"){
			alert("该栏目已是顶级栏目!");
			return false;
		}else{
			if(fla=="batch"){
				if(confirm("确实要移动栏目吗？")){
					 $.post("${ctx}/category/category-batchcatmove.action?ids="+idS+"&parentId=top",function(data){
							alert("移动成功");
							window.location.reload(); 
							self.parent.leftframe.loadCatetree(true,true,'ztree_cat');
					}); 
				}
			}else{
				if(confirm("确实要移动栏目吗？")){
					
					 $.post("${ctx}/category/category-catmove.action?category.categoryId="+srcid+"&parentId=top",function(data){
							alert("移动成功");
							window.location.reload(); 
							self.parent.leftframe.loadCatetree(true,true,'ztree_cat');
					}); 
				}
			}
		}
	}); 


}

//批量审核人设置
function batchAuthorSet(){
	    var ids = inputvalue();
	    var myDate = new Date();
		if(!ids){
			alert("您未选择任何一个");
			check_bind="no";
			return;		
		}else{
			check_bind="yes";
		}
			 $.post("${ctx}/topic/topic-authorset.action?ids="+ids+"&myTime="+myDate,function(data){				
					if(data=="sorroy"){
						alert("您没有权限");
					} else{
						 authorSelect();
						 batch = "batchs";
					}
				});
	
}
//审核人设置-选择审核人
function authorSelect(){
	$.getJSON("${ctx}/category/category-authorsetselect.action",function(data){
		var htmlStr = "";
		var authorArray = new Array(data.length);
		for(var i=0;i<data.length;i++){
			var adminId = data[i].adminId;
			var loginName = data[i].loginName;
			var realName=data[i].realName;
			if(realName==null){
				authorArray[i]="<li><input name=\"autor\"  type='checkbox' value='"+loginName+"'>&nbsp;<a id='siteStatus"+i+"'>"+loginName+"</a></li>";
			}else{
				authorArray[i]="<li><input name=\"autor\"  type='checkbox' value='"+loginName+"'>&nbsp;<a id='siteStatus"+i+"'>"+loginName+"</a>&nbsp;&nbsp;<a id='realName"+i+"'>"+realName+"</a></li>";
			}		
		}
		htmlStr = authorArray.join("");
		$("#authorSetDiv").html("<ul id='shenheul'>"+htmlStr+"</ul>");
});
}

//审核人设置-保存审核人到数据库
function authorSet(){
	 var ids = inputvalue();
	 var arr = new Array();
		$("#authorSetDiv").find('input:checkbox[name="autor"]:checked').each(function(i,item){
			 var s = $(item).val();
			 arr.push(s);
		});
	    var  str = arr.join(',');
	    	 $.get("${ctx}/category/category-authorset.action?ids="+ids+"&adminName="+str,function(data){
				if(data == "ok"){
					alert("设置审核人成功");
		  			window.location.reload(); 
				}
			});  
}

//弹出文章迁移界面
function moveContent(){
	var ids = inputvalue();
	idS = ids;
	disabled_ids = ids;
    var arr = ids.split("@");     
    loadZTree(arr ,'treeDiv_MoveContent');	
}
/**加载ztree  初始化 */
function loadZTree(arr ,ztreeId){  
	loadCatetree(true,false,ztreeId);    
    var treeObj = $.fn.zTree.getZTreeObj(ztreeId);
    for(var i=0;i<arr.length;i++){
    	var node = treeObj.getNodeByParam("id",arr[i], null);
    	if(node){
    		node.nocheck = true; 
    		treeObj.updateNode(node);
    	}
    }
}

//执行迁移动作
function goMoveContent(){
	var treeObj = $.fn.zTree.getZTreeObj('treeDiv_MoveContent');
	nodes = treeObj.getCheckedNodes(true);
    if(nodes){
    	var targetId = nodes[0].id;
		if(confirm("确实要迁移栏目下的文章吗？")){
			$.post("${ctx}/category/category-movecontent.action?ids="+idS+"&targetId="+targetId,function(data){
				if(data == "ok"){
					alert("文章迁移成功");
					window.location.reload(); 
				}else if(data == "zoro"){
					alert("栏目下没有文章");
				} else{
					alert("文章迁移失败");
				}
			});
		}
    }	 
}

function reloadTree(){
	var flag = <s:property value="refresh"/> ;
	if(!flag){
		 if (window.navigator.userAgent.indexOf("Chrome")>=0){
				window.parent.frames["leftframe"].contentWindow.window.loadCatetree(true,true,'ztree_cat');
			 }
			else{
				window.parent.frames["leftframe"].window.loadCatetree(true,true,'ztree_cat');
			} 			
	}
}
	</script>
<link href="${ctx}/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${ctx}/js/jquery.ztree.core-3.0.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.ztree.excheck-3.0.js"></script>
<script type="text/javascript">
  function loadCatetree (type,needUrl,id){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/sitetree.action?t="+new Date().getTime(),
		data:{"type":type,"needurl":needUrl},
		type:"post",
		dataType:"text",
		success:function(ss){
			var setting = {
					check: {
						enable: true,
						chkStyle: "radio",
						radioType: "all"
					},
					data: {
						simpleData: {
							enable: true
						}
					}
				};

			var zNodes = eval('('+ss+')');
			$.fn.zTree.init($("#"+id), setting, zNodes);
			 
		}
	});
} 	
  $(function(){
		if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
			$('#main_box').width($('#main_box').width()-25);
		}
	});
</script>